<?php
declare (strict_types=1);

namespace app\api\controller\v1;

use app\common\model\Banner;
use app\common\model\Paper as PaperModel;

class Paper
{
    /**
     * 历年考卷
     *
     * @return \think\Response
     */
    public function index()
    {
        return sucessMsg(200, '获取成功', [
            'banner' => $this->banner(),   //获取banner
            'paper' => $this->paper(),   //获取试卷
        ]);
    }

    /**
     * 轮播图
     *
     * @return \think\Response
     */
    public function banner()
    {
        $data = Banner::where(['type'=>2, 'status'=>1])
            ->field('image')
            ->withAttr('image',function ($val, $data){
                return strtolower(config("app.domain_url").str_replace('\\', '/', $val));
            })
            ->order(['id' => 'asc'])
            ->select();
        return $data;
    }

    /**
     * 试卷
     *
     * @return \think\Response
     */
    public function paper()
    {
        $data =PaperModel::where(['status'=>1])
            ->field('image,title')
            ->withAttr('image',function ($val, $data){
                return strtolower(config("app.domain_url").str_replace('\\', '/', $val));
            })
            ->limit(0,8)
            ->order(['id' => 'asc'])
            ->select();
        return $data;
    }

}

